<?php
/**
 * Created by PhpStorm.
 * User: Raytine
 * Date: 2019/11/21
 * Time: 22:35
 */

namespace App\Service;


use Illuminate\Support\Facades\Storage;

class MiniProgramService
{
    protected $app;

    public function __construct()
    {
            $this->app=app('mini.agent');
    }

    /**
     * @param $value
     * @return bool|int
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
     */
    public function miniCode($value,$path){
        $filename='user'.$value;
        $response = $this->app->app_code->getUnlimit($value, [
            'page'  => $path,
            'width' => 600,
        ]);
        if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
            if (!Storage::exists($filename)){
                Storage::put( $filename,$response->getBodyContents());
            }
        }
        return $filename;
    }
}